package pl.edu.agh.ssm.monitor.listeners;

import java.util.HashMap;

import pl.edu.agh.ssm.monitor.data.SessionMedia;
import pl.edu.agh.ssm.monitor.data.SessionMediaType;

public class RtpAVPMediaTypeInfoProvider implements MediaTypeInfoProvider{

	private HashMap<Integer, SessionMedia> knownMedia;
	private SessionMedia unknownMedia;
	
	public RtpAVPMediaTypeInfoProvider() {
		knownMedia = new HashMap<Integer, SessionMedia>();
		unknownMedia = new SessionMedia(SessionMediaType.OTHER, "Unknown", 0);
		rfc3551Initialization();
	}
	
	public SessionMedia getMediaTypeInfo(int payloadType) {
		SessionMedia result = knownMedia.get(Integer.valueOf(payloadType));
		if(result == null) {
			result = unknownMedia;
		}
		return result;
	}
	
	/**
	 * Add informations from dynamic payloads
	 * @param payloadType Dynamic payload value (by default is grater than 95)
	 * @param mediaInfo Media description
	 */
	public void addMediaTypeInfo(int payloadType, SessionMedia mediaInfo) {
		knownMedia.put(Integer.valueOf(payloadType), mediaInfo);
	}
	
	private void rfc3551Initialization() {
		/* --------- AUDIO ------------- */
		knownMedia.put(Integer.valueOf(0), 
				new SessionMedia(SessionMediaType.AUDIO, "PCMU", 8000));
		knownMedia.put(Integer.valueOf(3), 
				new SessionMedia(SessionMediaType.AUDIO, "GSM", 8000));
		knownMedia.put(Integer.valueOf(4), 
				new SessionMedia(SessionMediaType.AUDIO, "G723", 8000));
		knownMedia.put(Integer.valueOf(5), 
				new SessionMedia(SessionMediaType.AUDIO, "DVI4", 8000));
		knownMedia.put(Integer.valueOf(6), 
				new SessionMedia(SessionMediaType.AUDIO, "DVI4", 16000));
		knownMedia.put(Integer.valueOf(7), 
				new SessionMedia(SessionMediaType.AUDIO, "LPC", 8000));
		knownMedia.put(Integer.valueOf(8), 
				new SessionMedia(SessionMediaType.AUDIO, "PCMA", 8000));
		knownMedia.put(Integer.valueOf(9), 
				new SessionMedia(SessionMediaType.AUDIO, "G722", 8000));
		knownMedia.put(Integer.valueOf(10), 
				new SessionMedia(SessionMediaType.AUDIO, "L16", 44100));
		knownMedia.put(Integer.valueOf(11), 
				new SessionMedia(SessionMediaType.AUDIO, "L16", 44100));
		knownMedia.put(Integer.valueOf(12), 
				new SessionMedia(SessionMediaType.AUDIO, "QCELP", 8000));
		knownMedia.put(Integer.valueOf(13), 
				new SessionMedia(SessionMediaType.AUDIO, "CN", 8000));
		knownMedia.put(Integer.valueOf(14), 
				new SessionMedia(SessionMediaType.AUDIO, "MPA", 90000));
		knownMedia.put(Integer.valueOf(15), 
				new SessionMedia(SessionMediaType.AUDIO, "G728", 8000));
		knownMedia.put(Integer.valueOf(16), 
				new SessionMedia(SessionMediaType.AUDIO, "DVI4", 11025));
		knownMedia.put(Integer.valueOf(17), 
				new SessionMedia(SessionMediaType.AUDIO, "DVI4", 22050));
		knownMedia.put(Integer.valueOf(18), 
				new SessionMedia(SessionMediaType.AUDIO, "G729", 8000));
		/*--------- VIDEO --------------- */
		knownMedia.put(Integer.valueOf(25), 
				new SessionMedia(SessionMediaType.VIDEO, "CellB", 90000));
		knownMedia.put(Integer.valueOf(26), 
				new SessionMedia(SessionMediaType.VIDEO, "JPEG", 90000));
		knownMedia.put(Integer.valueOf(28), 
				new SessionMedia(SessionMediaType.VIDEO, "nv", 90000));
		knownMedia.put(Integer.valueOf(31), 
				new SessionMedia(SessionMediaType.VIDEO, "H261", 90000));
		knownMedia.put(Integer.valueOf(32), 
				new SessionMedia(SessionMediaType.VIDEO, "MPV", 90000));
		knownMedia.put(Integer.valueOf(33), 
				new SessionMedia(SessionMediaType.VIDEO, "MP2T", 90000));
		knownMedia.put(Integer.valueOf(34), 
				new SessionMedia(SessionMediaType.VIDEO, "H263", 90000));
		
	}
}
